<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>函数封装set数据集合去重</title>
	</head>
	<body>
		
		<script type="text/javascript">
			let  str = "1234567899987";
			let arr = [1,2,3,4,53,2];
			//判断元素类型
		    function toGetType(data)
			{
				if(typeof data == "string")
				{
					return typeof data;
				}
				else if(typeof data == "object")
				{
					return Object.prototype.toString.call(data).slice(8,-1);
				}
			}
			function UserSetRmRpt(data)
			{
				let set;
				if(toGetType(data) == "string")
				{
				let newArr = Array.from(data)
				set  = new Set(newArr);	
				return Array.from(set).join("");
				}
				else if(toGetType(data) == "Array")
				{
					set  = new Set(data);
					return Array.from(set);
				}
			}
			console.log(UserSetRmRpt(str));
			console.log(UserSetRmRpt(arr));
		</script>
	</body>
</html>
